<?php
class Menu extends Tree {
    protected $name;
    protected $description;
    protected $menu;
    public function __construct($name, $description)
    {
        $this->name         = $name;
        $this->description  = $description;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
    public function setDescription($description)
    {
        $this->description = $description;
    }

    public function add(Tree $menu)
    {
        $this->menu[] = $menu;
    }

    public function set($i, Tree $menu)
    {
        if (array_key_exists($i, $this->menu))
        {
            $this->menu[$i] = $menu;
        }
    }

    public function removeByKey($i)
    {
        if (array_key_exists($i, $this->menu))
        {
            unset($this->menu[$i]);
        }
    }
    public function removeByMenu(Tree $menu)
    {
        foreach ($this->menu as $i => $m)
        {
            if ($m === $menu)
            {
                unset($this->menu[$i]);
            }
        }
    }

    public function getKey($i)
    {
        if (array_key_exists($i, $this->menu))
        {
            return $this->menu[$i];
        }
        return false;
    }

    public function getPrint(){
        echo "<br>";
        echo "menu: ".$this->name;
        echo "<br>";
        echo "description: ".$this->description;
        echo "<br>";
        foreach ($this->menu as $key => $m)
        {
            $m->getPrint();
        }
    }
}